package com.dcy.znoa.domain;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.dcy.znoa.common.enums.OperTypeCode;
import com.dcy.znoa.common.enums.SexCode;
import com.dcy.znoa.domain.attendance.AttRule;
import com.dcy.znoa.domain.publiz.Company;
import com.dcy.znoa.domain.publiz.Department;
import com.dcy.znoa.domain.publiz.Duty;
import com.dcy.znoa.domain.sys.UrlListTreeVo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("sys_oper")
public class Oper {


    public static final Long SYS_OPER_ID = 999999L;
    public static final String DEFAULT_PASSWORD ="123456";

    @TableId(type = IdType.AUTO, value = "oper_id")
    Long operId;
    /*
    * 1：平台管理员；2：企业管理员；3：企业用户;4：园区管理员；5：物业管理员；6：物业普通员工
    * */
    @TableField("oper_type")
    Integer operType;

    @TableField("phone_no")
    String phoneNo;

    @TableField("oper_name")
    String operName;

    @TableField("password")
    String password;

    @TableField("comp_id")
    Long compId;//归属企业id；如果归属是园区，这个字段就是园区 ID

    @TableField(exist = false)
    String compName;

    @TableField("dep_id")
    Long depId;

    @TableField(exist = false)
    String depName;

    @TableField("is_dep_duty")
    Integer isDepDuty;

    @TableField("duty_id")
    Long dutyId;

    @TableField(exist = false)
    String dutyName;

    @TableField("duty_no")
    Integer dutyNo;

    @TableField(exist = false)
    String dutyNoStr;

    @TableField("superior_id")
    Long superiorId;

    @TableField("sex")
    Integer sex;

    @TableField("id_card")
    String idCard;

    @TableField("employee_no")
    String employeeNo;

    @TableField("head_pic")
    String headPic;

    @TableField("qr_code")
    String qrCode;

    @TableField("account")
    String account;

    @TableField("email")
    String email;

    @TableField("push_id")
    String pushId;//极光推送ID

    /**
     * 考勤规则编号：一天有多次上下班时，考勤规则编号一样，序号不一样，序号从前到后
     一般是按照考勤规则编号这个字段来作为其他表的外键。
     数据的合理性放到前端页面去控制
     * */
    @TableField("att_rule_no")
    Integer attRuleNo;//规则编号

    @TableField("last_time")
    Date lastTime;

    @TableField("create_time")
    Date createTime;

    @TableField("create_oper_name")
    String createOperName;

    @TableField("update_time")
    Date updateTime;

    @TableField("update_oper_name")
    String updateOperName;

    @TableField("is_audit")
    Integer isAudit;//

    @TableField("audit_oper_name")
    String auditOperName;

    @TableField("valid_flag")
    Integer validFlag = 1;


    @TableField(exist = false)
    Company company;

    @TableField(exist = false)
    Department department;

    @TableField(exist = false)
    Duty duty;

    @TableField(exist = false)
    AttRule attRule;//考勤规则
    @TableField(exist = false)
    Long attRuleId;//考勤规则ID

    @TableField(exist = false)
    String ruleName;//规则名称

    @TableField(exist = false)
    Integer total;

    @TableField(exist = false)
    Date applyTime;

    @TableField(exist = false)
    Date attTime;

    @TableField(exist = false)
    List<UrlListTreeVo> urlListTreeVoList;


    public Oper(String phoneNo) {
        this.phoneNo = phoneNo;
    }

    public static Map<String,Object> toMap(Oper oper) {
        Map<String, Object> map  = new HashMap<String, Object>();
        map.put("operId",oper.getOperId());
        map.put("operType", OperTypeCode.getMsgByCode(oper.getOperType()));
        map.put("phoneNo",oper.getPhoneNo());
        map.put("operName",oper.getOperName());
        map.put("compId",oper.getCompId());
        map.put("compName",oper.getCompName());

        map.put("depId",oper.getDepId());
        map.put("depName",oper.getDepName());
        map.put("isDepDuty",oper.getIsDepDuty());
        map.put("dutyId",oper.getDutyId());
        map.put("dutyName",oper.getDutyName());
        map.put("dutyNo",oper.getDutyNo());
        map.put("superiorId",oper.getSuperiorId());
        map.put("sex", SexCode.getMsgByCode(oper.getSex()));
        map.put("idCard",oper.getIdCard());
        map.put("qrCode",oper.getQrCode());
        return  map;
    }


//    @TableField("push_id")
//    private String pushId;
}
